//Test for Ventus NLE
//vus_frame

#include "vus_test_public_includes.h"
#include "vus_test.h"
#include "vus_test_frame.h"
#include "vus_test_private_includes.h"

#include <libavformat/avformat.h>


//TODO: support different pixel formats
vus_frame *vus_frame_create(int width, int height, int linesize) {
	vus_frame *frame = (vus_frame *)malloc(sizeof(vus_frame));
	if (frame == NULL)
		return NULL;
		
	frame->width = width;
	frame->height = height;
	frame->linesize[0] = linesize;
	frame->buffer_size = linesize *height;
	frame->data[0] = (uint8_t *)av_malloc( frame->buffer_size );
	if (frame->data == NULL)
		return NULL;
	
	return frame;
}

vus_frame *vus_frame_copy(int width, int height, uint8_t *data, int linesize) {
	vus_frame *frame = vus_frame_create(width, height, linesize);
	if (!frame)
		return NULL;
	
	memcpy(frame->data[0], data, frame->buffer_size);
	return frame;
}

void vus_frame_free(vus_frame **frame) {
	vus_frame *f = *frame;
	av_free (f->data[0]);
	free(*frame);
	frame = 0;
}
